<template>
    <div class="user_member">
        <wrapper-content pageTitle="新增股票">
            <div class="data-content">
                <Form ref="addcontent" :model="formValidate" label-position="right" :label-width="100" :rules="ruleValidate" class="system_stock_add">
                    <FormItem label="类型：" prop="type" style="width: 250px">
                        <Select v-model="formValidate.type" placeholder="">
                            <Option value="shang">上证</Option>
                            <Option value="shen">深证</Option>
                        </Select>
                    </FormItem>
                    <FormItem label="代码：" prop="code" style="width: 500px">
                        <Input v-model="formValidate.code" />
                    </FormItem>
                    <FormItem label="名称：" prop="name" style="width: 500px">
                        <Input v-model="formValidate.name" />
                    </FormItem>
                    <FormItem label="拼音：" prop="pinyin" style="width: 500px">
                        <Input v-model="formValidate.pinyin" />
                    </FormItem>

                    <!--修改部分-->
                    <div v-if="method == 'edit'">
                        <FormItem label="可买：" prop="type" style="width: 250px">
                            <Select v-model="formValidate.canbuy" placeholder="">
                                <Option value="true">可买</Option>
                                <Option value="false">不可买</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="可买升：" prop="type" style="width: 250px">
                            <Select v-model="formValidate.canbuyup" placeholder="">
                                <Option value="true">可买</Option>
                                <Option value="false">不可买</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="可买跌：" prop="canbuydown" style="width: 250px">
                            <Select v-model="formValidate.canbuydown" placeholder="">
                                <Option value="true">可买</Option>
                                <Option value="false">不可买</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="可卖：" prop="cansale" style="width: 250px">
                            <Select v-model="formValidate.cansale" placeholder="">
                                <Option value="true">可卖</Option>
                                <Option value="false">不可卖</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="停牌：" prop="canstop" style="width: 250px">
                            <Select v-model="formValidate.canstop" placeholder="">
                                <Option value="true">无停牌</Option>
                                <Option value="false">停牌</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="点差：" prop="diff" style="width: 500px">
                            <Input v-model="formValidate.diff" />
                        </FormItem>
                        <FormItem label="停牌时间：" prop="stoptime" style="width: 500px">
                            <DatePicker :value="formValidate.stoptime" @on-change="changeEndDate" :editable="false" type="date" style="width: 100%"></DatePicker>

                        </FormItem>
                    </div>

                    <Form-item label="板块：" prop="plate">
                        <Transfer
                                :data="data1"
                                :target-keys="formValidate.plate"
                                :render-format="render1"
                                @on-change="handleChange1"></Transfer>
                    </Form-item>
                    <FormItem>
                        <Button type="ghost" shape="circle" icon="arrow-return-left"
                                @click="$router.push({path:'/system/stock'})">
                            返回
                        </Button>

                        <Button type="primary" @click="handleSubmit('addcontent')">确定</Button>

                    </FormItem>
                </Form>
            </div>
        </wrapper-content>

    </div>
</template>
<style>
    .system_stock_add .ivu-form-item{
        margin-bottom: 2px;
    }
</style>
<script>
    import WrapperContent from '../../../components/wrapper-content.vue'
    import {getUserList, getUser, getLevelList, getPositionList,doUserInfo,delUser,changeUserState} from "@/api/user";
    import * as utils from '../../../assets/js/utils'
    import $ from 'jquery'
    import _ from 'lodash'

    export default {
        components: {
            WrapperContent
        },
        data() {
            return {
                self: this,
                method:'add',
                editid : 0,
                formValidate: {
                    type:'shang',
                    code:'',
                    name:'',
                    pinyin:'',
                    canbuy:'true',
                    canbuyup:'true',
                    canbuydown:'true',
                    cansale:'true',
                    canstop:'true',
                    stoptime:'',
                    diff:'0',
                    plate:this.getTargetKeys(),
                },
                ruleValidate: {
                    code: [
                        {required: true, message: '请输入股票代码', trigger: 'blur'}
                    ],
                    name: [
                        {required: true, message: '请输入股票名称', trigger: 'blur'}
                    ],
                    pinyin: [
                        {required: true, message: '请输入股票拼音', trigger: 'blur'}
                    ],
                    plate: [
                        {required: true, message: '[板块]:必须选择！', trigger: 'blur'}
                    ],
                },
                data1: this.getMockData(),
                targetKeys1: this.getTargetKeys()
            }
        },

        created: function () {
            this.loading = false ;
            this.editid = this.$route.params.id;
            if(this.$route.params.id > 0 ){
                this.method = 'edit';
            }else{
                this.method = 'add';
            }
        },
        methods: {
            handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.$Message.success('Success!');
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            getMockData () {
                let mockData = [];
                for (let i = 1; i <= 20; i++) {
                    mockData.push({
                        key: i.toString(),
                        label: 'Content ' + i,
                        description: 'The desc of content  ' + i,
                        disabled: Math.random() * 3 < 1
                    });
                }
                return mockData;
            },
            getTargetKeys () {
                return this.getMockData()
                    .filter(() => Math.random() * 2 > 1)
                    .map(item => item.key);
            },
            render1 (item) {
                return item.label;
            },
            handleChange1 (newTargetKeys, direction, moveKeys) {
                console.log(newTargetKeys);
                console.log(direction);
                console.log(moveKeys);
                this.formValidate.plate = newTargetKeys;
            },
            changeEndDate(date) {
                this.formValidate.stoptime = date;
            },
        }
    }
</script>

















































